package com.MTR;

import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class HealthCheckPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4371379654060314306L;

	
	// battery table
	JTable table = null;
	DefaultTableModel dtm = null;
	
	
	HealthCheckPanel()
	{
		// add the image.
		Image myPicture = null;
		try {
			File img = new File("images/cross.jpg");
			myPicture = ImageIO.read(img).getScaledInstance(141, 108, Image.SCALE_DEFAULT);
		} catch (IOException e) {
			e.printStackTrace();
		}
        final JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
        this.add( picLabel );
        
        // add the battery list
 		JPanel scrollPanel = new JPanel();
 		scrollPanel.setBorder(BorderFactory.createTitledBorder("Low Battery Warning"));
 		
 		// put the result into a table
 		//Object[][] cellData = {{"row1-col1", "row1-col2", "a", "b","c"}};
 		//
 		String[] columnNames = {"Vechile ID", "Node ID", "Battery Status"};
 		this.dtm = new DefaultTableModel(columnNames, 0);
 		this.table = new JTable(dtm);
 		
 		// add the table into a scroll pane
 		JScrollPane tableScrollPanel=new JScrollPane(table);
 		scrollPanel.add(tableScrollPanel);
 		
 		this.add(scrollPanel);
 		
 		// FIXME remove fake data for battery
 		Object [][]rows = {
 				{"1", "1", "low"},
 				{"2", "1", "normal"},
 				{"3", "1", "high"},
 				{"4", "1", "low"},
 				{"5", "1", "low"}
 		};
 		for(Object[] o : rows)
 		{
 			this.dtm.addRow(o);
 		}
 		
 		
	}
	
}
